package com.zhou;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;


/**
 * Hello world!
 *
 */
@SpringBootApplication
@EnableScheduling
public class App 
{
    public static void main( String[] args ) {
        SpringApplication.run(App.class, args);

    }

    @Autowired
    private RabbitTemplate template;

    @Autowired
    private Queue helloWorldQueue;

    //@Scheduled(fixedDelay = 1000, initialDelay = 500)
    public void send() {
        String message = "Hello World!";
        this.template.convertAndSend(helloWorldQueue.getName(), message);
        System.out.println(" [x] Sent '" + message + "'");
    }

    @RabbitListener(queues = "hello.world.queue")
    public void receive(String in) {
        System.out.println(" [x] Received '" + in + "'");
    }


}
